import os
from pathlib import Path


def init_python_project(project_dir: str = '.', project_name: str = 'my_obj', author: str = "your_name"):
    """
    Initialize a Python project structure with standard directories and files.

    Creates a project directory structure with 'core', 'utils', and 'test' subdirectories,
    along with basic Python files including __init__.py files, a main.py, utility files,
    README.md, and setup.py configuration.

    Args:
        project_dir (str): Root directory for the project (default: current directory)
        project_name (str): Name of the project (default: 'my_obj')
        author (str): Author name for setup.py (default: 'Your Name')

    Returns:
        None

    Raises:
        OSError: If directory creation fails
    """

    root = Path(project_dir).absolute()
    root.mkdir(parents=True, exist_ok=True)

    dirs_to_create = [
        root,
        root / "core",
        root / "utils",
        root / 'test'
    ]

    try:
        for i in dirs_to_create:
            i.mkdir(exist_ok=True, parents=True)
    except OSError as e:
        raise OSError(f'failed to create file structure {i}, e: {e}')

    files = {
        "core/__init__.py": "",
        "core/main.py": "print('Hello')",
        "utils/util_1.py": "import unittest\n...",
        "README.md": " readme ",
        "setup.py": f"""
from setuptools import setup, find_packages

setup(
    name="{project_name}",
    version="0.1",
    author="{author}",
    packages=find_packages()
)
        """.strip()
    }

    for rel_path, content in files.items():
        path = root / rel_path
        path.write_text(content, encoding="utf-8")
        print(f"Created: {path}")

    print(f"\nProject '{project_name}' initialized successfully!")


if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(
        description="Initialize a Python project structure.")
    parser.add_argument("-d", "--project_dir", help="directory of the project")
    parser.add_argument("-n", "--name", default="my_project",
                        help="Name of the project")
    parser.add_argument("-a", "--author", default="yk", help="Author name")

    args = parser.parse_args()

    init_python_project(
        project_dir=args.project_dir,
        project_name=args.name,
        author=args.author
    )
